package com.lh.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lh.commonutils.R;
import com.lh.entity.TOrder;
import com.lh.entity.vo.OrderQuery;
import com.lh.service.ITOrderService;
import com.lh.servicebase.utils.JwtUtils;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author lh
 * @since 2021-06-16
 */
@RestController
@RequestMapping("/order")
public class TOrderController {


    @Autowired
    private ITOrderService orderService;

    @PostMapping("createOrder/{courseId}")
    public R saveOrder(@PathVariable String courseId, HttpServletRequest request){


//        System.out.println(JwtUtils.getMemberIdByJwtToken(request)+"111111111111111111111111111111111111111111111");
//        创建订单，返回订单号
         String  orderNo = orderService.creatOrders(courseId, JwtUtils.getMemberIdByJwtToken(request));
        return R.ok().data("orderId",orderNo);
    }
//根据订单id查询点订单信息
    @GetMapping("getOrderInfo/{orderId}")
    public  R getOrderInfo(@PathVariable String orderId){
        QueryWrapper<TOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderId);
        TOrder one = orderService.getOne(wrapper);

        return  R.ok().data("item",one);

    }

    @ApiOperation(value = "订单列表")
    @PostMapping("findAllOrder/{page}/{limit}")
    public R findAllOrder(@PathVariable Integer page, @PathVariable Integer limit, @RequestBody(required =false)OrderQuery orderQuery){

      R r = orderService.findAllOrder(page,limit,orderQuery);
      return r;
    }

    @ApiOperation(value = "利润列表")
    @PostMapping("moneyList/{page}/{limit}")
    public R moneyList(@PathVariable Integer page,@PathVariable Integer limit,@RequestBody(required =false)OrderQuery orderQuery){
        System.out.println(orderQuery.getTeacherName());
      R r= orderService.moneymoneyList(page,limit,orderQuery.getTeacherName());
      return r;
    }

    @ApiOperation("记录每天的订单数")
    @GetMapping("countOrder/{day}")
    public Integer countOrder(@PathVariable String day) {

        Integer count= orderService.countOrder(day);
        return count;

    }

}

